#include "HistogramDialog.h"
#include "ImageInfo.h"



HistogramDialog::HistogramDialog (QWidget *parent)
: AbstractDialog (parent)
{
  ui.setupUi(this);
}



void HistogramDialog::_openEvent ()
{
  ui.histogramPreviewer->clearChannel ();
  ImageInfo info (__pWork->getDoc ()->getPreview ());
  HistogramChannel grayChannel (info.getGrayHistogram (), 
          QColor (200, 200, 200), tr ("Gray"), true);
  ui.histogramPreviewer->addChannel (grayChannel);
  ui.chkGray->setChecked (true);

  if (__pWork->getDoc ()->getFormat () != QImage::Format_Indexed8)
  {
    HistogramChannel redChannel (info.getRedHistogram (), 
      QColor (255, 0, 0), tr ("Red"), true);
    ui.histogramPreviewer->addChannel (redChannel);
    HistogramChannel greenChannel (info.getGreenHistogram (), 
      QColor (0, 255, 0), tr ("Green"), true);
    ui.histogramPreviewer->addChannel (greenChannel);
    HistogramChannel blueChannel (info.getBlueHistogram (), 
      QColor (0, 0, 255), tr ("Blue"), true);
    ui.histogramPreviewer->addChannel (blueChannel);
    ui.chkRed->setChecked (true);
    ui.chkRed->setEnabled (true);
    ui.chkGreen->setChecked (true);
    ui.chkGreen->setEnabled (true);
    ui.chkBlue->setChecked (true);
    ui.chkBlue->setEnabled (true);
  } else {
    ui.chkRed->setChecked (false);
    ui.chkRed->setEnabled (false);
    ui.chkGreen->setChecked (false);
    ui.chkGreen->setEnabled (false);
    ui.chkBlue->setChecked (false);
    ui.chkBlue->setEnabled (false);
  }
  ui.histogramPreviewer->update ();
}



void HistogramDialog::_closeEvent (int r)
{

}

void HistogramDialog::toggleRedChannel (bool isChecked)
{
  ui.histogramPreviewer->setChannelShow (tr ("Red"), isChecked);
  ui.histogramPreviewer->update ();
}

void HistogramDialog::toggleGreenChannel (bool isChecked)
{
  ui.histogramPreviewer->setChannelShow (tr ("Green"), isChecked);
  ui.histogramPreviewer->update ();
}

void HistogramDialog::toggleBlueChannel (bool isChecked)
{
  ui.histogramPreviewer->setChannelShow (tr ("Blue"), isChecked);
  ui.histogramPreviewer->update ();
}

void HistogramDialog::toggleGrayChannel (bool isChecked)
{
  ui.histogramPreviewer->setChannelShow (tr ("Gray"), isChecked);
  ui.histogramPreviewer->update ();
}
